﻿using MCUPackage;
using MCUPackage.DesignEditor;
using MCUPackage.Utils;
using System;
using System.ComponentModel;

namespace SxPackages.STC8.Models
{
	[Serializable]
	class USART1Options : USARTOptionBase
	{
		private string mPins = "P3.0,P3.1";
		[DisplayName("使用引脚"),
		DefaultValue("P3.0,P3.1"),
		Description("本串口使用的引脚设置"),
		TypeConverter(typeof(StringCollectionConvertor)),
		MultiCollection(new string[] { "P3.0,P3.1", "P3.6,P3.7", "P1.6,P1.7"})]
		public string Pins
		{
			get => mPins;
			set
			{
				if (value != mPins)
				{
					if (SwitchPins(value, mPins))
					{
						mPins = value;
					}
				}
			}
		}

		protected override void SetPins(String[] aPins)
		{
			var opt = mParent.SetPinPurpose(aPins[0], PinPurpose.USART1_RCV);
			opt.Mode = GPIOMode.Standard;
			opt.Speed = GPIOSpeed.Fast;
			opt.EnableUp = true;
			opt = mParent.SetPinPurpose(aPins[1], PinPurpose.USART1_SND);
			opt.Mode = GPIOMode.Push;
			opt.Speed = GPIOSpeed.Fast;
		}

		public USART1Options(STC8HUSOP20 aParent) : base(aParent)
		{
			Id = 1;
			mUsePins = TemplateHelper.GetPins(mPins);
		}
	}
}
